package xianchengpool;

import xianchenglock.I;

import java.util.concurrent.*;

/**
 * @功能
 * @创建时间 2019/12/26
 */
public class T06_Future {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask<Integer> task = new FutureTask<>(()->{ //Callable类型
            TimeUnit.MILLISECONDS.sleep(500);
            return 1000;
        });
        new Thread(task).start();
        System.out.println(task.get()); //阻塞,会等待任务执行，执行完才拿到返回值
        //*********************
        ExecutorService service = Executors.newFixedThreadPool(5);
        Future<Integer> f = service.submit(()->{
            TimeUnit.MILLISECONDS.sleep(500);
          return 1;
        });
      //  System.out.println(f.get());
        System.out.println(f.isDone());  //get放前面执行完的话就是true，get会等待线程执行完
        System.out.println(f.get());
        System.out.println(f.isDone());
    }
}
